class Solution {
public:
    int ret = 0;
    int jk(TreeNode* root){
        if(root == NULL) return 0;
        
        int left = jk(root->left);
        int right = jk(root->right);
        
        if(left == 0 && right == 0){
            return 1;
        }
        if(left == 1 || right == 1){
            ret++;
            return 2;
        }
        return 0;
        
    }
    int minCameraCover(TreeNode* root) {
        if(root->left == NULL && root->right == NULL) return 1;
        if(root == NULL) return 0;
        
        int mf = jk(root);
        if(mf == 1) ret++;
        return ret;
    }
};
